﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Frame.Lib.Core.Role;
using Frame.Lib.Utilities;


public partial class Admin_Role_Edit : PageEdit
{
    private RoleBO Role
    {
        get
        {
            return RoleBO.Instance<RoleBO>();
        }
    }
    private string RoleID
    {
        get
        {
            if (Request["ID"] != null)
            {
                return StrUtil.DecryptDES(Request["ID"]);
            }
            else
            {
                return null;
            }
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            WebUtil.BindListControlWithEnum(TypeID, typeof(RoleType));
            TypeID.Items.RemoveAt(0);
            if (RoleID != null && RoleID != "")
            {
                DispInfo();
            }
        }
    }

   
    private void DispInfo()
    {
        RoleInfo info = Role.GetInfo(RoleID);
        EntityUtil.SetControl(pnlMain, info);
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        string strName = Name.Text.Trim();
        bool flag = Role.Exist(strName, RoleID);

        if (flag)
        {
            JSUtil.Alert("该角色已存在");
        }
        else
        {
            RoleInfo info = Role.GetInfo(RoleID);

            EntityUtil.SetEntity(pnlMain, info);

            Role.Save(info);
            JSUtil.RefreshView();
        }
    }
}
